<template>
    <div
      ref="elementRef"
      class="draggable flex "
      :class="{ 'is-dragging': isDragging, 'is-overed': isOvered }"
    >
      <slot :handleDragStart="handleDragStart" />
    </div>
  </template>

<script setup lang="ts" name="DraggableWrap">
  import { useDraggable } from '@vue-dnd-kit/core';
  import { computed } from 'vue';

  const props = defineProps<{
    source: Array<any>
    index: Number
  }>();

  const { elementRef, handleDragStart, isDragging, isOvered } = useDraggable({
    data: computed(() => ({
      index: props.index,
      source: props.source,
    })),
  });
</script>

<style scoped>
  .draggable {
    display: flex;
    flex-direction: row;
    padding: 10px 16px;
    border: 1px solid #3eaf7c;
    border-radius: 6px;
    cursor: move;
    background-color: #3eaf7c;
    color: white;
    font-weight: 500;
    font-size: 14px;
    width: 100%;
    transition: all 0.2s ease;
    align-items: center;
    justify-content:space-between;
    box-shadow: 0 2px 4px rgba(62, 175, 124, 0.2);
    background-color: #44c98d;
    user-select: none;
    touch-action: none;
  }

  .draggable:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(62, 175, 124, 0.3);
  }

  .is-dragging {
    opacity: 0.3;
  }

  .is-over {
     opacity: 0.7;
  }
  </style>